From 5fc1f2af0c2c9f97847f096b612532e187dbd099 Mon Sep 17 00:00:00 2001
From: Nicky Sielicki <me@nicky.io>
Date: Sun, 1 Nov 2015 16:51:19 -0600
Subject: [PATCH] Needs Testing: VGA and GM45 textmode fixes

See thread here:
http://www.coreboot.org/pipermail/coreboot/2015-October/080523.html

VGA Documentation here:
http://www.osdever.net/FreeVGA/vga/vga.htm#register

Changes in src/drivers/pc80/vga/vga.c:
	* Ensure CR lock bit isn't set before vga_textmode_init()
          and vga_set_mode()

        in src/northbridge/intel/gm45/gma.c
	* Ensure screen disable sequencer register is unset after
	  textmode init
	* use sizeof() when looping over u8 cr registers.

I'm unsure this would fix GM45 textmode graphics, but it's at
least a start.

Change-Id: Iae3d393ed4f39164c486672b08deb6187fd269ca
Signed-off-by: Nicky Sielicki <me@nicky.io>
---
 src/drivers/pc80/vga/vga.c       | 8 ++++++++
 src/northbridge/intel/gm45/gma.c | 3 ++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/drivers/pc80/vga/vga.c b/src/drivers/pc80/vga/vga.c
index 3ec8f54..a922be7 100644
--- a/src/drivers/pc80/vga/vga.c
+++ b/src/drivers/pc80/vga/vga.c
@@ -109,6 +109,10 @@ vga_mode_set(int hdisplay, int hblankstart, int hsyncstart, int hsyncend,
 	     int vsyncstart, int vsyncend, int vblankend, int vtotal,
 	     int stride)
 {
+	/* ensure everything is unlocked.
+	 * That's a 0 in the 7th bit of cr 0x11 */
+	vga_cr_write(0x11, vga_cr_read(0x11) & (~(0x1 << 7)));
+
 	/* htotal: 2080 */
 	htotal /= 8;
 	htotal -= 5;
@@ -294,6 +298,10 @@ vga_line_write(unsigned int line, const char *string)
 void
 vga_textmode_init(void)
 {
+	/* ensure everything is unlocked.
+	 * That's a 0 in the 7th bit of cr 0x11 */
+	vga_cr_write(0x11, vga_cr_read(0x11) & (~(0x1 << 7)));
+
 	vga_sr_write(0x00, 0x01); /* clear reset */
 	vga_sr_write(0x01, 0x00);
 
diff --git a/src/northbridge/intel/gm45/gma.c b/src/northbridge/intel/gm45/gma.c
index 3dd051c..efee554 100644
--- a/src/northbridge/intel/gm45/gma.c
+++ b/src/northbridge/intel/gm45/gma.c
@@ -148,7 +148,7 @@ static void intel_gma_init(const struct northbridge_intel_gm45_config *info,
 	};
 	vga_cr_write(0x11, 0);
 
-	for (i = 0; i <= 0x18; i++)
+	for (i = 0; i < sizeof(cr)/sizeof(u8); i++)
 		vga_cr_write(i, cr[i]);
 
 	power_port(mmio);
@@ -202,6 +202,7 @@ static void intel_gma_init(const struct northbridge_intel_gm45_config *info,
 		write32(mmio + LGC_PALETTE(0) + 4 * i, i * 0x010101);
 #else
 	vga_textmode_init();
+	vga_sr_write(1, vga_sr_read(1) & ~0x20); // Enable screen.
 #endif
 
 	/* Find suitable divisors.  */
-- 
1.9.1

